import { AxiosResponse } from "axios";
import { reactive } from "vue";
import {Response} from "@/api/type"
export const usePage = (api:(data:Record<string,unknown>)=>Promise<AxiosResponse<Response>>) => {
  const info = reactive({
    params: {
      page: 1,
      page_size: 5,
    },
    list: [],
    total: 0,
  });
  const requestApi = async (otherParams:Record<string,unknown> = {}) => {
    try {
      const params = Object.assign({}, info.params, otherParams);
      const {
        data: { data },
      } = await api(params);
      info.list = data.list;
      info.total = data.count;
    } catch (error) {
      console.log("error is", error);
    }
  };
  return {
    requestApi,
    info,
  };
};
